package com.yty.demo._4_oop;

/**
 * @author: yangtaoyao
 * @time: 2020/1/7 11:26
 * @description:
 */
public class Person {
    private String name;
    private String city;
    private int age;
    public int publicanInt;

    public Person() {
        name="张三";
        age=20;
    }

    public void showName(){
        System.out.println(this.name);
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public void showAge(){
        System.out.println(this.age);
    }

    public void addAge(){
        this.age++;
    }

    //函数重载
    public int reload(){
        System.out.println("reload 1");
        return 0;
    }
    public void reload(int x,float f){
        System.out.println("reload 2");
    }
    public void reload(float f,int x){
        System.out.println("reload 3");
    }

    /**
     * 可变个数形参
     */
    public void printInfo(String...arg){
        for (String s:arg){
            System.out.println(s);
        }
    }

    public static void main(String[] args) {
        Person p1=new Person("小明",18);
        Person p2=new Person("小华",23);
        p1.showAge();
        p2.showAge();
        p1.addAge();
        p2.addAge();
        p1.showAge();
        p2.showAge();

        p1.reload();
        p1.reload(1,2f);
        p1.reload(2f,1);

        System.out.println("-------可变形参个数--------");
        p1.printInfo(p1.getName(),p1.getCity(),String.valueOf(p1.getAge()));
    }
}
